package com.ijiangtao.studevtech.demo.log.day.DT20170429;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;

/**
 * 
 *
 */
public class SLF4JDemo 
{
	//slf4j
	private static Logger LOGGER = LoggerFactory.getLogger(SLF4JDemo.class);
	//log4j
	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SLF4JDemo.class);  
	
    public static void main( String[] args )
    {
    	/*log4j 自定义日志输出级别 */
    	LOG.setLevel(org.apache.log4j.Level.INFO);
    	LOG.trace("~~~~~~~~~~log4j LOG.trace="+dateToString(new Date()));
    	LOG.debug("~~~~~~~~~~log4j LOG.debug="+dateToString(new Date()));
    	LOG.info("~~~~~~~~~~log4j LOG.info="+dateToString(new Date()));
    	LOG.warn("~~~~~~~~~~log4j LOG.warn="+dateToString(new Date()));
    	LOG.error("~~~~~~~~~~log4j LOG.error="+dateToString(new Date()));
    	LOG.fatal("~~~~~~~~~~log4j LOG.fatal="+dateToString(new Date()));
		
    	/*logback*/
    	LOGGER.trace("--------logback LOG.trace="+dateToString(new Date()));
    	LOGGER.debug("--------logback LOG.trace="+dateToString(new Date()));
    	LOGGER.info("--------logback LOG.trace="+dateToString(new Date()));
    	LOGGER.warn("--------logback LOG.trace="+dateToString(new Date()));
    	LOGGER.error("--------logback LOG.trace="+dateToString(new Date()));

    }
    
 /** 
  * 将java.util.Date 格式转换为字符串格式'yyyy-MM-dd HH:mm:ss'(24小时制)<br> 
  * 如Sat May 11 17:24:21 CST 2002 to '2002-05-11 17:24:21'<br> 
  * @param time Date 日期<br> 
  * @return String   字符串<br> 
  */ 
  public static String dateToString(Date time){ 
      SimpleDateFormat formatter; 
      formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 
      String ctime = formatter.format(time); 
      return ctime; 
  } 

}
